﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using BrainTechLLC.Silverlight.InputControls;
using System.Windows.Shapes;

namespace BrainTechLLC.Silverlight.InputControls2
{
    [TemplatePart(Name = "imgInfo", Type = typeof(Image))]
    [TemplatePart(Name = "lblPrompt", Type = typeof(TextBlock))]
    [TemplatePart(Name = "txtDateHint", Type = typeof(ContentControl))]
    [TemplatePart(Name = "stackTop", Type = typeof(StackPanel))]
    [TemplatePart(Name = "bottomLine", Type = typeof(Rectangle))]
    public partial class InputBaseControl : Control, IInputControl2
    {
        protected StackPanel _stackTop;
        protected Image _imgInfo;
        protected ContentControl _txtDateHint;
        protected TextBlock _lblPrompt;
        protected bool ShiftKeyDown;
        protected Rectangle _bottomLine;

        protected Brush OldBackground;

        public static readonly DependencyProperty ValidatingTypeProperty = DependencyProperty.Register(
            "ValidatingType", typeof(Type), typeof(InputBaseControl), new PropertyMetadata(new PropertyChangedCallback(ValidatingTypeChanged)));

        public static readonly DependencyProperty ControlReviewStateProperty = DependencyProperty.Register(
            "ControlReviewState", typeof(ReviewState2), typeof(InputBaseControl), new PropertyMetadata(ReviewState2.None, new PropertyChangedCallback(ReviewStateChanged)));

        public static readonly DependencyProperty ShowDateHintProperty = DependencyProperty.Register(
            "ShowDateHint", typeof(bool), typeof(InputBaseControl), new PropertyMetadata(true, new PropertyChangedCallback(ShowDateHintChanged)));

        public static readonly DependencyProperty ShowBottomLineProperty = DependencyProperty.Register(
            "ShowBottomLine", typeof(bool), typeof(InputBaseControl), new PropertyMetadata(true, new PropertyChangedCallback(ShowDateHintChanged)));

        public static readonly DependencyProperty LabelTextStringProperty = DependencyProperty.Register(
            "LabelTextString", typeof(string), typeof(InputBaseControl), new PropertyMetadata(string.Empty, new PropertyChangedCallback(LabelTextChanged)));

        public static readonly DependencyProperty HelpTextStringProperty = DependencyProperty.Register(
            "HelpTextString", typeof(string), typeof(InputBaseControl), new PropertyMetadata(string.Empty, new PropertyChangedCallback(TextChanged)));

        public static readonly DependencyProperty ImageIconProperty = DependencyProperty.Register(
            "ImageIcon", typeof(Image), typeof(InputBaseControl), new PropertyMetadata(null, new PropertyChangedCallback(ImageChanged)));

        public static readonly DependencyProperty BackgroundForInputControlFocusProperty = DependencyProperty.Register(
            "BackgroundForInputControlFocus", typeof(Brush), typeof(InputBaseControl),
            new PropertyMetadata(InputControlConstants.HighlightFocusBrush, new PropertyChangedCallback(BackgroundForInputControlFocusChanged)));

        public static readonly DependencyProperty ValidationTypeProperty = DependencyProperty.Register(
            "ValidationType", typeof(ValidationType), typeof(InputBaseControl), new PropertyMetadata(ValidationType.NONE, new PropertyChangedCallback(ValidationTypeChanged)));

        public static readonly DependencyProperty BackgroundForControlFocusProperty = DependencyProperty.Register(
            "BackgroundForControlFocus", typeof(Brush), typeof(InputBaseControl),
            new PropertyMetadata(InputControlConstants.LightGrayBrush, new PropertyChangedCallback(BackgroundForControlFocusChanged)));

        public static readonly DependencyProperty BackgroundForInfoProperty = DependencyProperty.Register(
            "BackgroundForInfo", typeof(Brush), typeof(InputBaseControl), new PropertyMetadata(InputControlConstants.WhiteBrush, new PropertyChangedCallback(BackgroundForInfoChanged)));

        public static readonly DependencyProperty BackgroundForValidProperty = DependencyProperty.Register(
            "BackgroundForValid", typeof(Brush), typeof(InputBaseControl), new PropertyMetadata(InputControlConstants.GreenValid, new PropertyChangedCallback(BackgroundForValidChanged)));

        public static readonly DependencyProperty BackgroundForNoneProperty = DependencyProperty.Register(
            "BackgroundForNone", typeof(Brush), typeof(InputBaseControl), new PropertyMetadata(InputControlConstants.WhiteBrush, new PropertyChangedCallback(BackgroundForNoneChanged)));

        public static readonly DependencyProperty BackgroundForNotSetProperty = DependencyProperty.Register(
            "BackgroundForNotSet", typeof(Brush), typeof(InputBaseControl), new PropertyMetadata(InputControlConstants.WhiteBrush, new PropertyChangedCallback(BackgroundForNotSetChanged)));

        public static readonly DependencyProperty BackgroundForInvalidProperty = DependencyProperty.Register(
            "BackgroundForInvalid", typeof(Brush), typeof(InputBaseControl), new PropertyMetadata(InputControlConstants.RedError, new PropertyChangedCallback(BackgroundForInvalidChanged)));

        public static readonly DependencyProperty BackgroundForWarningProperty = DependencyProperty.Register(
            "BackgroundForWarning", typeof(Brush), typeof(InputBaseControl), new PropertyMetadata(InputControlConstants.BrightYellowWarning, new PropertyChangedCallback(BackgroundForWarningChanged)));

        public static readonly DependencyProperty LabelFontSizeProperty = DependencyProperty.Register(
            "LabelFontSize", typeof(double), typeof(InputBaseControl), new PropertyMetadata(10.0, new PropertyChangedCallback(LabelFontSizePropChanged)));

        public double LabelFontSize
        {
            get { return (double)GetValue(LabelFontSizeProperty); }
            set { SetValue(LabelFontSizeProperty, value); }
        }

        private static void LabelFontSizePropChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputBaseControl t = (InputBaseControl)d;
            t.LabelFontSize = (double)e.NewValue;
            t.UpdateLabelFontSize();
        }

        public void UpdateLabelFontSize()
        {
            if (_lblPrompt != null)
                _lblPrompt.FontSize = LabelFontSize;
        }

        public static readonly DependencyProperty LabelForegroundProperty = DependencyProperty.Register(
            "LabelForeground", typeof(Brush), typeof(InputBaseControl), new PropertyMetadata(new SolidColorBrush(Colors.Black), new PropertyChangedCallback(LabelForegroundPropChanged)));

        public Brush LabelForeground
        {
            get { return (Brush)GetValue(LabelForegroundProperty); }
            set { SetValue(LabelForegroundProperty, value); }
        }

        private static void LabelForegroundPropChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputBaseControl t = (InputBaseControl)d;
            t.LabelForeground = (Brush)e.NewValue;
            t.UpdateLabelForeground();
        }

        public void UpdateLabelForeground()
        {
            if (_lblPrompt != null)
                _lblPrompt.Foreground = LabelForeground;
        }

        public Type ValidatingType
        {
            get { return (Type)GetValue(ValidatingTypeProperty); }
            set { SetValue(ValidatingTypeProperty, value); }
        }

        public ValidationType ValidationType
        {
            get { return (ValidationType)GetValue(ValidationTypeProperty); }
            set { SetValue(ValidationTypeProperty, value); }
        }

        private static void LabelTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputBaseControl t = (InputBaseControl)d;
            t.LabelTextString = e.NewValue as string;
            UpdatePromptTextBindings(t, e.NewValue as string);
        }

        private static void ValidatingTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputBaseControl t = (InputBaseControl)d;
            t.ValidatingType = (Type)e.NewValue;
            t.UpdateValidatingType();
        }

        private static void ValidationTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputBaseControl t = (InputBaseControl)d;
            t.ValidationType = (ValidationType)e.NewValue;
            t.UpdateValidationType();
        }

        protected virtual void UpdateValidationType()
        {
        }

        protected virtual void UpdateValidatingType()
        {
        }

        public static void UpdatePromptTextBindings(InputBaseControl obj, string newText)
        {
            obj.UpdatePromptText();
        }

        public void UpdatePromptText()
        {
            if (_lblPrompt != null)
                _lblPrompt.Text = LabelTextString;
        }


        public string HelpTextString
        {
            get { return (string)GetValue(HelpTextStringProperty); }
            set { SetValue(HelpTextStringProperty, value); }
        }

        public Image ImageIcon
        {
            get { return (Image)GetValue(ImageIconProperty); }
            set { SetValue(ImageIconProperty, value); }
        }

        public string LabelTextString
        {
            get { return (string)GetValue(LabelTextStringProperty); }
            set { SetValue(LabelTextStringProperty, value); }
        }

        public Brush BackgroundForInputControlFocus
        {
            get { return (Brush)GetValue(BackgroundForInputControlFocusProperty); }
            set { SetValue(BackgroundForInputControlFocusProperty, value); }
        }

        public Brush BackgroundForValid
        {
            get { return (Brush)GetValue(BackgroundForValidProperty); }
            set { SetValue(BackgroundForValidProperty, value); }
        }

        public Brush BackgroundForInfo
        {
            get { return (Brush)GetValue(BackgroundForInfoProperty); }
            set { SetValue(BackgroundForInfoProperty, value); }
        }

        public Brush BackgroundForInvalid
        {
            get { return (Brush)GetValue(BackgroundForInvalidProperty); }
            set { SetValue(BackgroundForInvalidProperty, value); }
        }

        public Brush BackgroundForNotSet
        {
            get { return (Brush)GetValue(BackgroundForNotSetProperty); }
            set { SetValue(BackgroundForNotSetProperty, value); }
        }

        public Brush BackgroundForControlFocus
        {
            get { return (Brush)GetValue(BackgroundForControlFocusProperty); }
            set { SetValue(BackgroundForControlFocusProperty, value); }
        }

        public Brush BackgroundForNone
        {
            get { return (Brush)GetValue(BackgroundForNoneProperty); }
            set { SetValue(BackgroundForNoneProperty, value); }
        }

        public Brush BackgroundForWarning
        {
            get { return (Brush)GetValue(BackgroundForWarningProperty); }
            set { SetValue(BackgroundForWarningProperty, value); }
        }

        public ReviewState2 ControlReviewState
        {
            get { return (ReviewState2)GetValue(ControlReviewStateProperty); }
            set { SetValue(ControlReviewStateProperty, value); }
        }

        public bool ShowDateHint
        {
            get { return (bool)GetValue(ShowDateHintProperty); }
            set { SetValue(ShowDateHintProperty, value); }
        }


        public bool ShowBottomLine
        {
            get { return (bool)GetValue(ShowBottomLineProperty); }
            set { SetValue(ShowBottomLineProperty, value); }
        }
        
        private static void TextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputBaseControl t = (InputBaseControl)d;
            t.HelpTextString = e.NewValue as string;
            UpdateHelpTextBindings(t, e.NewValue as string);
        }

        public static void UpdateHelpTextBindings(InputBaseControl obj, string newText)
        {
            obj.UpdateHelpTextBinding();
        }

        public void UpdateHelpTextBinding()
        {
            _base.PrivateSetTooltipText(this, HelpTextString);
        }

        private static void ImageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputTextBox t = (InputTextBox)d;
            t.ImageIcon = e.NewValue as Image;
            UpdateImageIconBindings(t, e.NewValue as Image);
        }

        private static void BackgroundForControlFocusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputTextBox t = (InputTextBox)d;
            t.BackgroundForControlFocus = e.NewValue as Brush;
            UpdateBackgroundForControlFocusBindings(t, e.NewValue as Brush);
        }

        private static void BackgroundForInputControlFocusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputTextBox t = (InputTextBox)d;
            t.BackgroundForInputControlFocus = e.NewValue as Brush;
            UpdateBackgroundForInputControlFocusBindings(t, e.NewValue as Brush);
        }

        public static void UpdateBackgroundForInputControlFocusBindings(InputTextBox obj, Brush newBackground)
        {
            obj.UpdateBackgroundForInputControlFocus();
        }

        public static void UpdateImageIconBindings(InputTextBox obj, Image newImage)
        {
            obj.UpdateImageIconBinding();
        }

        public static void UpdateBackgroundForControlFocusBindings(InputTextBox obj, Brush newBackground)
        {
        }

        private static void BackgroundForValidChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputTextBox t = (InputTextBox)d;
            t.BackgroundForValid = e.NewValue as Brush;
            UpdateBackgroundForValidBindings(t, e.NewValue as Brush);
        }

        public static void UpdateBackgroundForValidBindings(InputTextBox obj, Brush newBackground)
        {
            obj.UpdateBackgroundForValid();
        }

        public void UpdateBackgroundForValid()
        {
            if (PrimaryInputControl != null && ControlReviewState == ReviewState2.Valid)
                PrimaryInputControl.Background = BackgroundForValid;
        }


        private static void BackgroundForInfoChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputTextBox t = (InputTextBox)d;
            t.BackgroundForInfo = e.NewValue as Brush;
            UpdateBackgroundForInfoBindings(t, e.NewValue as Brush);
        }

        public static void UpdateBackgroundForInfoBindings(InputTextBox obj, Brush newBackground)
        {
            obj.UpdateBackgroundForInfo();
        }

        private static void BackgroundForNoneChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputTextBox t = (InputTextBox)d;
            t.BackgroundForNone = e.NewValue as Brush;
            UpdateBackgroundForNoneBindings(t, e.NewValue as Brush);
        }

        public static void UpdateBackgroundForNoneBindings(InputTextBox obj, Brush newBackground)
        {
            obj.UpdateBackgroundForNone();
        }

        private static void BackgroundForNotSetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputTextBox t = (InputTextBox)d;
            t.BackgroundForNotSet = e.NewValue as Brush;
            UpdateBackgroundForNotSetBindings(t, e.NewValue as Brush);
        }

        public static void UpdateBackgroundForNotSetBindings(InputTextBox obj, Brush newBackground)
        {
            obj.UpdateBackgroundForNotSet();
        }

        private static void BackgroundForInvalidChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputTextBox t = (InputTextBox)d;
            t.BackgroundForInvalid = e.NewValue as Brush;
            UpdateBackgroundForInvalidBindings(t, e.NewValue as Brush);
        }

        public static void UpdateBackgroundForInvalidBindings(InputTextBox obj, Brush newBackground)
        {
            if (obj.PrimaryInputControl != null && obj.ControlReviewState == ReviewState2.Invalid)
                obj.PrimaryInputControl.Background = newBackground;
        }

        private static void BackgroundForWarningChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputTextBox t = (InputTextBox)d;
            t.BackgroundForWarning = e.NewValue as Brush;
            UpdateBackgroundForWarningBindings(t, e.NewValue as Brush);
        }

        public static void UpdateBackgroundForWarningBindings(InputTextBox obj, Brush newBackground)
        {
            obj.UpdateBackgroundForWarnings();
        }

        public void UpdateBackgroundForWarnings()
        {
            if (PrimaryInputControl != null && ControlReviewState == ReviewState2.Warning)
                PrimaryInputControl.Background = BackgroundForWarning;
        }

        private static void ReviewStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputTextBox t = (InputTextBox)d;
            t.ControlReviewState = (ReviewState2)e.NewValue;
            UpdateControlReviewStateBindings(t, (ReviewState2)e.NewValue);
        }

        public static void UpdateControlReviewStateBindings(InputTextBox obj, ReviewState2 newState)
        {
            obj.SetControlState(newState);
        }

        private static void ShowDateHintChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputTextBox t = (InputTextBox)d;
            t.ShowDateHint = (bool)e.NewValue;
            UpdateShowDateHintBindings(t, (bool)e.NewValue);
        }

        private static void ShowBottomLineChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            InputTextBox t = (InputTextBox)d;
            t.ShowBottomLine = (bool)e.NewValue;
            t.UpdateShowBottomLine();
        }

        public void UpdateShowDateHint()
        {
            if (_txtDateHint != null)
                _txtDateHint.Visibility = (ValidatingType == typeof(DateTime) && ShowDateHint == true) ? Visibility.Visible : Visibility.Collapsed;
        }

        public static void UpdateShowDateHintBindings(InputTextBox obj, bool newState)
        {
            obj.UpdateShowDateHint();
        }

        public void UpdateImageIconBinding()
        {
            if (_imgInfo != null) _imgInfo = ImageIcon;
        }

        public virtual void UpdateBackgroundForInputControlFocus()
        {
        }

        protected NonInheritedBaseInputClass _base;

        /// <summary>
        /// This event is fired whenever the control's review state changes
        /// </summary>
        public event EventHandler<ObjectEventArgsNonRef<ReviewState2, string>> NotifyReviewStateChange;
        public event EventHandler<ObjectEventArgs<string>> ValueChanged;

        /// <summary>
        /// Returns the primary child control responsible for receiving user input
        /// </summary>
        public virtual Control PrimaryInputControl { get { return null; } }

        public object ParentSection { get; set; }

        void InputTextBox_Loaded(object sender, RoutedEventArgs e)
        {

        }

        public InputBaseControl()
            : base()
        {
            _base = new NonInheritedBaseInputClass();
            this.Loaded += new RoutedEventHandler(InputTextBox_Loaded);
            this.IsTabStop = false;
        }

        public void UpdateBackgroundForNone()
        {
            if (PrimaryInputControl != null && ControlReviewState == ReviewState2.None)
                PrimaryInputControl.Background = BackgroundForNone;
        }

        public void UpdateBackgroundForNotSet()
        {
            if (PrimaryInputControl != null && ControlReviewState == ReviewState2.NotSet)
                PrimaryInputControl.Background = BackgroundForNotSet;
        }

        public void UpdateBackgroundForInfo()
        {
            if (PrimaryInputControl != null && ControlReviewState == ReviewState2.Info)
                PrimaryInputControl.Background = BackgroundForInfo;
        }

        public void UpdateShowBottomLine()
        {
            if (_bottomLine != null)
                _bottomLine.Visibility = ShowBottomLine ? Visibility.Visible : Visibility.Collapsed;
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _imgInfo = base.GetTemplateChild("imgInfo") as Image;
            _txtDateHint = base.GetTemplateChild("txtDateHint") as ContentControl;
            _lblPrompt = base.GetTemplateChild("lblPrompt") as TextBlock;
            _stackTop = base.GetTemplateChild("stackTop") as StackPanel;
            _bottomLine = base.GetTemplateChild("bottomLine") as Rectangle;

            this.GotFocus += new RoutedEventHandler(InputTextBoxControl_GotFocus);
            this.LostFocus += new RoutedEventHandler(InputTextBoxControl_LostFocus);
            this.KeyDown += new KeyEventHandler(InputBaseControl_KeyDown);
            this.KeyUp += new KeyEventHandler(InputBaseControl_KeyUp);
            _imgInfo.MouseLeftButtonDown += new MouseButtonEventHandler(imgInfo_MouseLeftButtonDown);

            UpdateImageIconBinding();
            UpdateBackgroundForInputControlFocus();
            UpdateBackgroundForNone();
            UpdateShowDateHint();
            UpdateBackgroundForInfo();
            UpdateBackgroundForNotSet();
            UpdateBackgroundForWarnings();
            UpdateValidatingType();
            UpdateBackgroundForValid();
            UpdatePromptText();
            UpdateLabelFontSize();
            UpdateShowBottomLine();
            UpdateLabelForeground();
        }

        void InputBaseControl_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Shift)
                ShiftKeyDown = false;
        }

        void InputBaseControl_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Shift)
                ShiftKeyDown = true;
        }

        /// <summary>
        /// Reads the latest validation error and warning text, and supplies an appropriate corresponding title string
        /// </summary>
        //public virtual void ReadLatestErrorTextAndTitle(out string errorTextString, out string errorTitleString, bool forceBypassQuestionsToErrors)
        //{
        //    _base.ReadLatestErrorTextAndTitleBase(out errorTextString, out errorTitleString, forceBypassQuestionsToErrors);
        //}

        public virtual string Value
        {
            get { return string.Empty; }
            set { }
        }

        public void OnValueChanged(string newValue)
        {
            if (ValueChanged != null)
                ValueChanged(this, new ObjectEventArgs<string>(newValue));
        }

        public virtual void SetControlState(ReviewState2 controlState)
        {
            _base.SetControlState(controlState, this);
        }

        protected virtual void OnNotifyReviewStateChanged(string errorOrWarning)
        {
            if (NotifyReviewStateChange != null)
                NotifyReviewStateChange(this, new ObjectEventArgsNonRef<ReviewState2, string>(ControlReviewState, errorOrWarning));
        }

        private void imgInfo_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //ToolTip t = imgInfo.GetValue(ToolTipService.ToolTipProperty) as ToolTip;

            //if (t != null)
            //{
            //    Dispatcher.BeginInvoke(() => { t.IsOpen = !t.IsOpen; (PrimaryInputControl as Control).Focus(); });
            //}

            //if (App.EditHandler.IsEditMode)
            //    _base.ShowOrHideHelpText(stackHelp, this);
        }

        private void InputTextBoxControl_GotFocus(object sender, RoutedEventArgs e)
        {
            OldBackground = _stackTop.Background;
            _stackTop.Background = BackgroundForControlFocus;

            if (!ShiftKeyDown)
                PrimaryInputControl.Focus();
        }

        private void InputTextBoxControl_LostFocus(object sender, RoutedEventArgs e)
        {
            _stackTop.Background = OldBackground;

            if (_imgInfo != null)
            {
                ToolTip t = _imgInfo.GetValue(ToolTipService.ToolTipProperty) as ToolTip;

                if (t != null)
                    t.IsOpen = false;
            }
        }

        private void txtInput_KeyDown(object sender, KeyEventArgs e)
        {
        }

        private void txtInput_KeyUp(object sender, KeyEventArgs e)
        {
        }

        private void txtInput_GotFocus(object sender, RoutedEventArgs e)
        {
        }

        public virtual string ValidateContents()
        {
            return string.Empty;
            // return _base.ValidateContents(this);
        }

        //public void SetReviewStateForFailedRule(ValidationType failedRuleType)
        //{
        //    _base.SetReviewStateForFailedRule(failedRuleType, this);
        //}

        //public InputTextBox(ProfileElement ProfileElement)
        //{
        //    InitializeComponent();
        //    _base = new NonInheritedBaseInputClass();
        //    NotePanel = this.Notes;
        //    ProfileElement = (ProfileElement)ProfileElement;
        //    this.Loaded += new RoutedEventHandler(InputTextBox_Loaded);
        //    txtInput.Tag = ProfileElement;
        //    txtInput.DataType = (DataType)ProfileElement.DataTypeId;
        //    txtInput.Format = (TextFormat)ProfileElement.FormElementFormatId;
        //    txtInput.MaxLength = ProfileElement.FormFieldMaxLength > 0 ? ProfileElement.FormFieldMaxLength : 0;


        //    _base.SetInputControlBehavior(txtInput);
        //    txtInput.ParentControl = this;
        //    imgInfo.Source = App.MainPage.about.Source;
        //}

        //public void InitializeFromProfileElement()
        //{
        //    if (ProfileElement != null)
        //    {
        //        if (ControlReviewState != ReviewState.Invalid && ControlReviewState != ReviewState.Warning)
        //            _base.PrivateSetTooltipText(this, HelpTextString);
        //    }
        //}

    }
}


